package com.mes.service.manu;

import com.yy.base.common.dao.Dao;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

/**
 * pda 用色 按钮权限
 * @author wenye
 *
 */
@Service
public class PermissionService {

	@Autowired
	private Dao dao;
	
	/**
	 * 获取用户的按钮（流程定义）权限
	 * @return 
	 */
	public List<Map<String, Object>> getPermissionByUser(String userId, String processValue) {
		String sql = "select op.obuiapp_process_id, op.value process_value, op.name process_name " + 
				" from OBUIAPP_Process op, OBUIAPP_Process_Access opa, ad_role r, ad_user_roles ur " + 
				" where op.obuiapp_process_id=opa.obuiapp_process_id " + 
				"       and opa.ad_role_id=r.ad_role_id " + 
				"       and r.ad_role_id=ur.ad_role_id " + 
				"       and opa.isactive='Y' " + 
				"       and ur.ad_user_id=? ";
		if(StringUtils.isNotEmpty(processValue)) {
			sql += " and op.value='" + processValue + "'";
		}
		List<Map<String, Object>> list = this.dao.query(sql, userId);
		return list;
	}
	
	public List<Map<String, Object>> getPermissionByUser(String userId){
		return getPermissionByUser(userId, null);
	}
}
